<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$setting=$this->plugin_setting('basic');
$return['setting']=$setting;
if($_RQ['op']=='main'){
	$pid=$_RQ['pid'];
	if($pid){
		$return['group']=pdo_get('jy_zhaopin_job_group',array('id'=>$pid,'uniacid'=>$_SESSION['uniacid']),array('id','title','image','desc'));
	}
	$return['pcd']=$this->session('pcd')?:array();
	$setting=$this->plugin_setting('setting');
	$return['province']=file_get_contents('core/resource/area.txt');
	$return['province']=unserialize($return['province']);
	$return['pid']=$pid;
	$return['params']=array('keyword'=>'','cid'=>0,'pid'=>$pid);
	$return['member']=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('createtime','credit1','credit2','mobile','avatar','nickname'));
	$return['sharedata']=array(
		'title'=>$item_type['title'],
		'desc'=>$item_type['remark'],
		'link'=>custom_url('jy_zhaopin/groups//pid='.$pid.'&fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>tomedia($item_type['logo']),
	);
	set_html('title',$setting['title']?$setting['title'] :'信息列表');
	exi($return);
}
// js 获取数据
if($_RQ['op']=='getlist'){
	$params=array(
		'uniacid'=>$_SESSION['uniacid'],
		'status'=>1,
	);
	if(trim($_RQ['keyword'])){
		$params['title like']='%'.trim($_RQ['keyword']).'%';
		$return['params']['keyword']=trim($_RQ['keyword']);
	}
	if($_RQ['pid']){
		$params['pcate']=intval($_RQ['pid']);
		$return['params']['pcate']=intval($_RQ['pid']);
	}
	if($_RQ['cid']){
		$params['ccate']=intval($_RQ['cid']);
		$return['params']['ccate']=intval($_RQ['cid']);
	}
	if($_RQ['priceMin']){
		$params['price >=']=$_RQ['priceMin'];
		$return['params']['priceMin']=intval($_RQ['priceMin']);
	}
	if($_RQ['priceMax']){
		$params['price <=']=$_RQ['priceMax'];
		$return['params']['priceMax']=intval($_RQ['priceMax']);
		
	}
	$pcd=$this->session('pcd');
	if($pcd){
		$address=$pcd['province'].' '.$pcd['city'];
		$code=pdo_getcolumn('core_area',array('address'=>$address),'parent_code');
		$params['code']=$code;	
	}
	
	if($_RQ['type']>0){
		$params['type']=$_RQ['type'];
	}
	$psize = 20;
	if($_RQ['num']){
		$psize=$_RQ['num'];
	}
	$total='';
	$fields=array('id','title','ishot','images','mid','type','remark','createtime','price','looks');
	$orderby='paixu desc,id desc ';
	if($_RQ['order']){
		if($_RQ['order']=='looks'){
			$orderby='looks desc';
		}
		if($_RQ['order']=='price'){
			if($_RQ['order_type']==2){
				$orderby='price desc';
			}else{
				$orderby='price asc';
			}
			
		}
	}
	$pindex = max(1, intval($_RQ['page']));
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'fields'=>$fields,
		'orderby'=>$orderby,
	);
	$list=pdo_getslice('jy_zhaopin_job',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		$item['createtime']=date('Y-m-d H:m:s',$item['createtime']);
		$item['member']=pdo_get('core_members',array('id'=>$item['mid']));
		$item['images']=json_decode($item['images'],true);
		$item['isme']=$item['mid']==$_SESSION['uid'] ? 1 :0;
		$item['isshoucang']=pdo_getcolumn('jy_zhaopin_shoucang',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'itemid'=>$item['id']),'isshoucang');
		$item['msg']=pdo_getall('jy_zhaopin_comment',array('status'=>1,'uniacid'=>$_SESSION['uniacid'],'itemid'=>$item['id']),'','createtime desc');
		if($item['msg']){
			foreach($item['msg'] as &$m){
				$m['createtime'] = date('Y-m-d H:i',$m['createtime']);
				$m['member'] = pdo_get('core_members',array('id'=>$m['mid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','avatar','nickname'));
			}
		}
		$item['merchid']=pdo_getcolumn('jy_merch_user',array('mid'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),'id');
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='setmsg'){
	$postdata=get_postdata();
	$item=pdo_get('jy_zhaopin_job',array('uniacid'=>$_SESSION['uniacid'],'id'=>intval($postdata['pid'])));
	$data=array(
		'comment'=>trim($postdata['msg']),
		'mid'=>$_SESSION['uid'],
		'itemid'=>intval($postdata['pid']),
		//'cid'=>intval($postdata['cid']),
		'uniacid'=>$_SESSION['uniacid'],
		'item_mid'=>$item['mid'],
		'typeid'=>$item['type'],
		'status'=>1,
		'createtime'=>time(),
	);
	pdo_insert('jy_zhaopin_comment',$data);
	exi('评论成功！');
}
if($_RQ['op']=='shoucang'){
	$postdata=get_postdata();
	$id = intval($postdata['pid']);
	if(!$id){
		exi('没有找到该信息，请重新选择！','error');
	}
	$shoucang=pdo_get('jy_zhaopin_shoucang',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'itemid'=>$id));
	if($shoucang){
		if($shoucang['isshoucang'] !=1){
			pdo_update('jy_zhaopin_shoucang',array('isshoucang'=>1,'createtime'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'itemid'=>$id));
			exi('收藏成功');
		}else{
			pdo_update('jy_zhaopin_shoucang',array('isshoucang'=>0),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'itemid'=>$id));
		   exi('取消收藏');
		}
	}else{
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'itemid'=>$id,
			'mid'=>$_SESSION['uid'],
			'isshoucang'=>1,
			'createtime'=>TIMESTAMP
		);
		pdo_insert('jy_zhaopin_shoucang',$insert);
	}
	exi('收藏成功');
}
?>